package org.neptune.service.rabbit;

import java.util.Date;

import org.neptune.common.constant.NeptuneConstant;
import org.neptune.common.enums.LogType;
import org.neptune.common.util.RandomUtils;
import org.neptune.service.service.EsLogService;
import org.neptune.service.util.CommentMqBean;
import org.neptune.service.util.EsLogBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author lwl
 * @date 2019/11/25 14:45
 */
@Component
@RabbitListener(queues = NeptuneConstant.HOME_COMMENT_QUENE_NAME)
public class CommentConsumer {

	private static final Logger logger = LoggerFactory.getLogger(CommentConsumer.class);

	@Autowired
	private EsLogService esLogService;

	@RabbitHandler
	public void seckillLogProcess(CommentMqBean commentMqBean) {

		EsLogBean esLogBean = new EsLogBean();
		esLogBean.setId(RandomUtils.createRandomUUID());
		esLogBean.setContent(commentMqBean.getUserName() + " : "
				+ commentMqBean.getMsg());
		esLogBean.setCreateTime(new Date());
		esLogBean.setTitle(LogType.COMMENT_LOG.getName());
		esLogBean.setLogType(LogType.COMMENT_LOG.getCode());

		esLogService.addEsLog(esLogBean);
	}

}
